package main

func MinimumEditDistance(S, T string) int {
	lengthOfS := len(S)
	lengthOfT := len(T)
	var dp = [100][100]int{}

	min := func(a, b int) int {
		if a > b {
			return b
		}
		return a
	}
	//初始化
	for i := 0; i < lengthOfS; i++ {
		dp[i][0] = i
	}
	for j := 0; j < lengthOfT; j++ {
		dp[0][j] = j
	}

	for i := 1; i <= lengthOfS; i++ {
		for j := 1; j <= lengthOfT; j++ {
			delete := dp[i-1][j] + 1
			insert := dp[i][j-1] + 1
			replace := dp[i-1][j-1]

			if S[i-1] != T[j-1] {
				replace = dp[i-1][j-1] + 1
			}

			dp[i][j] = min(min(delete, insert), replace)
		}
	}
	return dp[lengthOfS][lengthOfT]
}
